Various small changes to cargo_test and friends.
authorNicolas Koch <nioko1337@gmail.com>
Sat, 12 Sep 2015 11:27:01 +0000 (13:27 +0200)
committerNicolas Koch <nioko1337@gmail.com>
Sat, 12 Sep 2015 11:27:01 +0000 (13:27 +0200)
- Reworked CargoTestError to contain Vec<ProcessError>
- Remove #[allow(trivial_casts)]
- Coding style fixes

src/cargo/ops/cargo_test.rs
src/cargo/util/errors.rs

index 6370f5c02ad5851698ad35e8e173a4d5850420b6..8b5ca97a5e8da132dc108ebc8581dfb72035d3b9 100644 (file)
@@ -27,7 +27,7 @@ pub fn run_tests(manifest_path: &Path,
 
     // If we have an error and want to fail fast, return
     if errors.len() > 0 && !options.no_fail_fast {
-        return Ok(Some(CargoTestError::from(&errors[..])))
+        return Ok(Some(CargoTestError::new(errors)))
     }
 
     // If a specific test was requested or we're not running any tests at all,
@@ -35,7 +35,7 @@ pub fn run_tests(manifest_path: &Path,
     if let ops::CompileFilter::Only { .. } = options.compile_opts.filter {
         match errors.len() {
             0 => return Ok(None),
-            _ => return Ok(Some(CargoTestError::from(&errors[..])))
+            _ => return Ok(Some(CargoTestError::new(errors)))
         }
     }
 
@@ -43,7 +43,7 @@ pub fn run_tests(manifest_path: &Path,
     if errors.len() == 0 {
         Ok(None)
     } else {
-        Ok(Some(CargoTestError::from(&errors[..])))
+        Ok(Some(CargoTestError::new(errors)))
     }
 }
 
@@ -56,7 +56,7 @@ pub fn run_benches(manifest_path: &Path,
     let errors = try!(run_unit_tests(options, &args, &compilation));
     match errors.len() {
         0 => Ok(None),
-        _ => Ok(Some(CargoTestError::from(&errors[..]))),
+        _ => Ok(Some(CargoTestError::new(errors))),
     }
 }
 
index 622e09c1ed2718c49b4a1dc18e775ad1e4019c9c..1d53d6fc84d8935f0aeef62ac807221c9039e26f 100644 (file)
@@ -55,7 +55,6 @@ impl<'a, T, F> ChainError<T> for F where F: FnOnce() -> CargoResult<T> {
 }
 
 impl<T, E: CargoError + 'static> ChainError<T> for Result<T, E> {
-    #[allow(trivial_casts)]
     fn chain_error<E2: 'static, C>(self, callback: C) -> CargoResult<T>
                          where E2: CargoError, C: FnOnce() -> E2 {
         self.map_err(move |err| {
@@ -114,7 +113,6 @@ pub struct ProcessError {
 
 impl Error for ProcessError {
     fn description(&self) -> &str { &self.desc }
-    #[allow(trivial_casts)]
     fn cause(&self) -> Option<&Error> {
         self.cause.as_ref().map(|s| s as &Error)
     }
@@ -138,7 +136,24 @@ impl fmt::Debug for ProcessError {
 pub struct CargoTestError {
     pub desc: String,
     pub exit: Option<ExitStatus>,
-    cause: Option<io::Error>,
+    pub causes: Vec<ProcessError>,
+}
+
+impl CargoTestError {
+    #[allow(deprecated)] // connect => join in 1.3
+    pub fn new(errors: Vec<ProcessError>) -> Self {
+        if errors.len() == 0 {
+            panic!("Cannot create CargoTestError from empty Vec")
+        }
+        let desc = errors.iter().map(|error| error.desc.clone())
+                                .collect::<Vec<String>>()
+                                .connect("\n");
+        CargoTestError {
+            desc: desc,
+            exit: errors[0].exit,
+            causes: errors,
+        }
+    }
 }
 
 impl fmt::Display for CargoTestError {
@@ -155,22 +170,8 @@ impl fmt::Debug for CargoTestError {
 
 impl Error for CargoTestError {
     fn description(&self) -> &str { &self.desc }
-    #[allow(trivial_casts)]
     fn cause(&self) -> Option<&Error> {
-        self.cause.as_ref().map(|s| s as &Error)
-    }
-}
-
-#[allow(deprecated)] // connect => join in 1.3
-impl<'a> From<&'a [ProcessError]> for CargoTestError {
-    fn from(errors: &[ProcessError]) -> Self {
-        if errors.len() == 0 { panic!("Cannot create CargoTestError from empty Vec") }
-        let desc = errors.iter().map(|error| error.desc.clone()).collect::<Vec<String>>().connect("\n");
-        CargoTestError {
-            desc: desc,
-            exit: errors[0].exit,
-            cause: None,
-        }
+        self.causes.get(0).map(|s| s as &Error)
     }
 }